package com.wdd.atcrowdfunding.manager.service.impl;

import com.wdd.atcrowdfunding.bean.Advertisement;
import com.wdd.atcrowdfunding.manager.dao.AdvertisementMapper;
import com.wdd.atcrowdfunding.manager.service.AdvertisementService;
import com.wdd.atcrowdfunding.util.Page;
import com.wdd.atcrowdfunding.vo.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdvertisementServiceImpl implements AdvertisementService{

    @Autowired
    private AdvertisementMapper advertisementMapper;

    @Override
    public int insertAdvertisement(Advertisement advertisement) {
        return advertisementMapper.insert(advertisement);
    }

    @Override
    public Page<Advertisement> pageQuery(Map<String, Object> advertMap) {
        Page<Advertisement> advertPage = new Page<Advertisement>((Integer)advertMap.get("pageno"),(Integer)advertMap.get("pagesize"));
        advertMap.put("startIndex", advertPage.getStartIndex());
        List<Advertisement> advertList= advertisementMapper.pageQuery(advertMap);
        // 获取数据的总条数
        int count = advertisementMapper.queryCount(advertMap);

        advertPage.setDatas(advertList);
        advertPage.setTotalsize(count);
        return advertPage;
    }

    @Override
    public int delete(Integer id) {
        return advertisementMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Advertisement selectAdvert(Integer id) {
        return advertisementMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteAdverts(Data ds) {
        return advertisementMapper.deleteBatchAdvertByVO(ds);
    }

    @Override
    public List<Advertisement> selectAdvertsByVo(Data ds) {
        return advertisementMapper.selectAdvertsByVo(ds);
    }

    @Override
    public Advertisement queryById(Integer id) {
        return advertisementMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateAdvert(Advertisement advertisement) {
        return advertisementMapper.updateByPrimaryKeySelective(advertisement);
    }

    @Override
    public List<Advertisement> selectByStatus(Integer status) {
        return advertisementMapper.selectByStatus(status);
    }

}
